﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataLib;

namespace EWMSWeb.Hardware
{
    public partial class AddControl : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["UserInfo"] != null)
                {
                    ListItem item = new ListItem();
                    item.Text = "--请选择--";
                    item.Value = "";
                    DataLib.BLL.City bllLib = new DataLib.BLL.City();

                    // 处理地
                    gcity.DataSource = bllLib.GetList(" flag1 ='02'");
                    gcity.DataTextField = "cityname";
                    gcity.DataValueField = "cityname";
                    gcity.DataBind();
                    gcity.Items.Insert(0, item);

                    // 归属地
                    bcity.DataSource = bllLib.GetList(" flag1 ='01'");
                    bcity.DataTextField = "cityname";
                    bcity.DataValueField = "cityname";
                    bcity.DataBind();
                    bcity.Items.Insert(0, item);

                    //User curUser = new DataLib.Accounts.Bus.User();
                    //dropGraphic.Enabled = false;
                    //curUser = (User)Session["UserInfo"];
                    //// dropGraphic.SelectedItem.Text = curUser.CompanyCity;
                    //hidusrName.Value = curUser.UserName;
                }
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (bcity.SelectedValue == "")
            {
                DataLib.Common.MessageBox.Show(Page, "请选择归属地");
                return;
            }
            if (gcity.SelectedValue == "")
            {
                DataLib.Common.MessageBox.Show(Page, "请选择处理地");
                return;
            }
            if (InsertHard() > 0)
            {
                DataLib.Common.MessageBox.Show(Page,"插入成功");
            }
            
        }

        /// <summary>
        /// 新增送检
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public int InsertHard()
        {
            DataLib.BLL.Hardware bll = new DataLib.BLL.Hardware();
            DataLib.Model.Hardware model = new DataLib.Model.Hardware();

                model.cjono = txtcjo.Value;
                model.loadno = txtload.Value;
                model.cjoremark = txtcjoremark.Value;
                model.boxcount = txtcount.Value;
                model.cumname = txtcumname.Value;
                model.cumcode = txtcumname.Value;
                model.saleman = txtman.Value;
 
                model.wrldate = txtcolldate.Value;
           
                model.bcity = bcity.SelectedValue;
           
                model.gcity = gcity.SelectedValue;

                model.flag1 =  "A"; //新增完成待送检   待初检   C 待硬件   D 待出库存 E出库完成
       
                return bll.Add(model);
           

        }
    }
}